package com.cqs.example.io.serial.utils;

import org.nustaq.serialization.FSTConfiguration;

/**
 * FST序列化方式
 */
public class FstSerializer {
    private static ThreadLocal<FSTConfiguration> config = new ThreadLocal<FSTConfiguration>(){
        @Override
        protected FSTConfiguration initialValue() {
            return FSTConfiguration.createDefaultConfiguration();
        }
    };
    private static FSTConfiguration getFST(){
        return config.get();
    }

    public static <T> byte[] serialize(T t) {
        return getFST().asByteArray(t);
    }

    public static <T> T deserialize(byte[] bytes) {
        return (T)getFST().asObject(bytes);
    }

}
